package com.javacode2018.lesson001.demo7;

import com.javacode2018.lesson001.demo5.IocUtil;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @Author: hongsir
 * @Date: 2024/10/10 - 10 - 10 - 10:46
 * @Description: com.javacode2018.lesson001.demo7
 * @Version: 1.0
 */
public class DependOnTset {
    /**
     * 无依赖的bean创建和销毁的顺序
     */
    @Test
    public void normalBean(){
        System.out.println("容器启动中！");
        String beanXml = "classpath:/com/javacode2018/lesson001/demo7/normalBean.xml";
        ClassPathXmlApplicationContext context = IocUtil.context(beanXml);
        System.out.println("容器启动完毕，准备关闭spring容器！");
        //关闭容器
        context.close();
        System.out.println("spring容器已关闭！");
    }

    /**
     * 强依赖的bean的创建和销毁顺序测试
     */
    @Test
    public void strongDependenceBean(){
        System.out.println("容器启动中！");
        String beanXml = "classpath:/com/javacode2018/lesson001/demo7/strongDependenceBean.xml";
        ClassPathXmlApplicationContext context = IocUtil.context(beanXml);
        System.out.println("容器启动完毕，准备关闭spring容器！");
        //关闭容器
        context.close();
        System.out.println("spring容器已关闭！");
    }

    /**
     * 通过depend-on来干预bean创建和销毁顺序
     */
    @Test
    public void dependOnBean(){
        System.out.println("容器启动中！");
        String beanXml = "classpath:/com/javacode2018/lesson001/demo7/dependOnBean.xml";
        ClassPathXmlApplicationContext context = IocUtil.context(beanXml);
        System.out.println("容器启动完毕，准备关闭spring容器！");
        //关闭容器
        context.close();
        System.out.println("spring容器已关闭！");
    }
}
